#include<jni.h>
#include <android/log.h>

char NativeKey[] = "0eplvqDJRbczhengjunNKDN-aa98C3ZBg4hangyingYyGaEjbxO9YMw";
char TRIPLEDES_KEY_BYTES[] = { 21, 37, 79, 88, -120, 16, 69, 56, 24, 37, 121,
		81, -53, -34, 85, 102, 119, 41, 116, -104, 55, 64, 54, -30 };

jobject Java_cn_edu_zjicm_wordsnet_1d_db_DatabaseKey_getReadableDatabase(
		JNIEnv *env, jobject thiz, jobject dbIn) {
//	__android_log_print(ANDROID_LOG_INFO, "JNIMsg", "C JNI  ---- > %s", "START");
	jclass dbInClass = (*env)->GetObjectClass(env, dbIn);//DataBaseHelper
	jclass dbOpenHelperClass = (*env)->GetSuperclass(env, dbInClass);
	if (dbOpenHelperClass) {
		jmethodID mid = (*env)->GetMethodID(env, dbOpenHelperClass,
				"getReadableDatabase",
				"(Ljava/lang/String;)Lnet/sqlcipher/database/SQLiteDatabase;");
		jstring key = (*env)->NewStringUTF(env, NativeKey);
		return (*env)->CallObjectMethod(env, dbIn, mid, key);
	}
}

jobject Java_cn_edu_zjicm_wordsnet_1d_db_DatabaseKey_getWritableDatabase(
		JNIEnv *env, jobject thiz, jobject dbIn) {
//	__android_log_print(ANDROID_LOG_INFO, "JNIMsg", "C JNI  ---- > %s", "START");
	jclass dbInClass = (*env)->GetObjectClass(env, dbIn);//DataBaseHelper
	jclass dbOpenHelperClass = (*env)->GetSuperclass(env, dbInClass);
	if (dbOpenHelperClass) {
		jmethodID mid = (*env)->GetMethodID(env, dbOpenHelperClass,
				"getWritableDatabase",
				"(Ljava/lang/String;)Lnet/sqlcipher/database/SQLiteDatabase;");
		jstring key = (*env)->NewStringUTF(env, NativeKey);
		return (*env)->CallObjectMethod(env, dbIn, mid, key);
	}
}

jbyteArray Java_cn_edu_zjicm_wordsnet_1d_db_DatabaseKey_getTripledesKeyBytes(
		JNIEnv *env, jobject thiz) {
//	__android_log_print(ANDROID_LOG_INFO, "JNIMsg", "C JNI  ---- > %s", "START");
	jbyteArray carr = (*env)->NewByteArray(env,24);
	(*env)->SetByteArrayRegion(env,carr,0,24,(jbyte *)TRIPLEDES_KEY_BYTES);
	return carr;
}
